<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <link href="https://cdn.bootcss.com/weui/1.1.3/style/weui.css" rel="stylesheet">
    <link rel="stylesheet" href="./style.css">
    <title>Shopping</title>
</head>

<body>
    <div class="container">
        <div class="page tabbar js_show">
            <div class="page__bd" style="height: 100%;">
                <div class="weui-tab">
                    <div class="weui-tab__panel tab show">
                        1
                    </div>
                    <div class="weui-tab__panel tab">
                        2
                    </div>
                    <div class="weui-tab__panel tab">
                        3
                    </div>
                    <div class="weui-tab__panel tab">
                        <div class="mine-title">我的</div>
                        <div class="mine-info">
                            <div class="weui-cell">
                                <div class="weui-cell__hd" style="position: relative;margin-right: 10px;">
                                    <img src="./images/user.jpg" style="width: 50px;display: block;border-radius: 50%">
                                </div>
                                <div class="weui-cell__bd">
                                    <p>联系人名称</p>
                                    <p style="font-size: 13px;color: #888888;">摘要信息</p>
                                </div>
                            </div>
                            <div class="weui-cells">
                                    <a class="weui-cell weui-cell_access weui-cell_example" href="javascript:;">
                                        <div class="weui-cell__hd"><img src="./images/shuiguoqu.png" alt="" style="width:20px;margin-right:16px;display:block"></div>
                                        <div class="weui-cell__bd weui-cell_primary">
                                            <p>文字标题</p>
                                        </div>
                                        <span class="weui-cell__ft">124</span>
                                    </a>
                                    <a class="weui-cell weui-cell_access weui-cell_example" href="javascript:;">
                                        <div class="weui-cell__hd"><img src="./images/shuiguojuan.png" alt="" style="width:20px;margin-right:16px;display:block"></div>
                                        <div class="weui-cell__bd weui-cell_primary">
                                            <p>文字标题</p>
                                        </div>
                                        <span class="weui-cell__ft"></span>
                                    </a>
                                </div>
                        </div>
                    </div>
                    <div class="weui-tabbar">
                        <a href="javascript:;" class="weui-tabbar__item weui-bar__item_on">
                            <span style="display: inline-block;position: relative;">
                                <img src="./images/fuchouzhelianmeng-heiguafu.png" alt="" class="weui-tabbar__icon">
                                <span class="weui-badge" style="position: absolute;top: -2px;right: -13px;">8</span>
                            </span>
                            <p class="weui-tabbar__label">微信</p>
                        </a>
                        <a href="javascript:;" class="weui-tabbar__item">
                            <img src="./images/kafei.png" alt="" class="weui-tabbar__icon">
                            <p class="weui-tabbar__label">通讯录</p>
                        </a>
                        <a href="javascript:;" class="weui-tabbar__item">
                            <span style="display: inline-block;position: relative;">
                                <img src="./images/lingdang.png" alt="" class="weui-tabbar__icon">
                                <span class="weui-badge weui-badge_dot"
                                    style="position: absolute;top: 0;right: -6px;"></span>
                            </span>
                            <p class="weui-tabbar__label">发现</p>
                        </a>
                        <a href="javascript:;" class="weui-tabbar__item">
                            <img src="./images/luonan.png" alt="" class="weui-tabbar__icon">
                            <p class="weui-tabbar__label">我</p>
                        </a>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <script>
        var doc = document;
        const choose = doc.querySelectorAll("a.weui-tabbar__item");
        // console.log(choose);
        const tabs = doc.querySelectorAll(".weui-tab__panel");
        for (let i = 0; i < choose.length; i++) {
            choose[i].addEventListener('click', function () {
                showTab.call(this);
            })
        }

        function showTab() {

            // this 表示 window，因为这个循环在 window 被调用，不是被点击的 a 标签

            for (let j = 0; j < tabs.length; j++) {
                if (choose[j] === this) {
                    choose[j].classList.add('weui-bar__item_on');
                    tabs[j].classList.add('show');
                } else {
                    choose[j].classList.remove('weui-bar__item_on');
                    tabs[j].classList.remove('show');
                }
            }
        }

    </script>
</body>

</html>